package com.ankang.art.service.impl;

import com.ankang.art.dto.AvgDto;
import com.ankang.art.dto.JudgesDto;
import com.ankang.art.dto.StudentDto;
import com.ankang.art.dto.TestIds;
import com.ankang.art.mapper.JudgesMapper;
import com.ankang.art.pto.JudgesPto;
import com.ankang.art.service.JudgesService;
import com.ankang.art.vo.Examinee;
import com.ankang.art.vo.Judges;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author:
 * Date:2020/3/17    19:43
 */
@Service
public class JudgesServiceImpl implements JudgesService {

    @Autowired
    JudgesMapper judgesMapper;
    @Override
    public void deleteJudges(String name) {
        judgesMapper.deleteJudges(name);
    }

    @Override
    public List<Judges> getJudges(String name, String status, String schoolName) {

        return judgesMapper.getJudges( name, status, schoolName);
    }

    @Override
    public void updateJudges(JudgesDto judgesDto) {
        judgesMapper.updateJudges(judgesDto);
    }

    @Override
    public void savaJudges(JudgesPto judgesPto) {
        judgesMapper.savaJudges(judgesPto);
    }

    @Override
    public Judges login(String name, String password) {
        Judges judges = judgesMapper.login(name,password);
        if(null!=judges){
            return judges;
        }else {
            return null;
        }
    }

    @Override
    public List<StudentDto> getExamineess() {

        List<StudentDto> list = new ArrayList<>();
        List<Examinee> examineess = judgesMapper.getExamineess();

        for (Examinee examinee:examineess) {
            System.out.println(examinee.getTest_id());
            Integer sum = judgesMapper.getTeacher(examinee.getTest_id());
            Float avgs = judgesMapper.getAvg(examinee.getId());
            StudentDto studentDto = new StudentDto();
            studentDto.setAvg(avgs);
             char[] characters = examinee.getName().toCharArray();
            studentDto.setName(characters[0]+"****");
            studentDto.setGender(examinee.getGender());
            studentDto.setId(examinee.getId());
            studentDto.setId_card(examinee.getId_card());
            studentDto.setTeacher_num(sum);
            studentDto.setStatus(examinee.getStatus());
            studentDto.setTestId(examinee.getTest_id());
            studentDto.setAge(examinee.getAge());
            list.add(studentDto);
        }

        return list;
    }

    @Override
    public void getAvg(AvgDto avgDto) {


        List<Integer> list = avgDto.getList();

        Integer id = avgDto.getId();

        judgesMapper.getAvg1(list.get(0),id);
        judgesMapper.getAvg2(list.get(1),id);
        judgesMapper.getAvg3(list.get(2),id);
        judgesMapper.getAvg4(list.get(3),id);
        judgesMapper.getAvg5(list.get(4),id);
        judgesMapper.getAvg6(list.get(5),id);
        judgesMapper.getAvg7(list.get(6),id);
        judgesMapper.getAvg8(list.get(7),id);
        judgesMapper.getAvg9(list.get(8),id);
        judgesMapper.getAvg10(list.get(9),id);



    }

    @Override
    public List<String> getTeachers(Integer testId) {


        return judgesMapper.getTeachers(testId);
    }

    @Override
    public List<Judges> getExamTeachers() {
        return judgesMapper.getExamTeachers();
    }

    @Override
    public void addExamTeachers(TestIds testIds) {
        Integer testId = testIds.getTestId();

        for(int i=0;i<testIds.getIds().size();i++){

            judgesMapper.addExamTeachers(testIds.getIds().get(i),testId);

        }
    }
    @Override
    public Boolean beginTest(Integer testId) {
        judgesMapper.beginTest(testId);
        return true;
    }
}
